//配置文件
var sysConfig = {};

//配置生存库服务器
var host = $api.getStorage('host');
if ( typeof host == 'undefined'||typeof host == '') {
    $api.setStorage('hostUnit', '集团');
    $api.setStorage('host', '180.153.49.253:58090');
    sysConfig.host = '180.153.49.253:58090';
} else {
    sysConfig.host = host;
}
//配置测试库服务器
//sysConfig.testHost = '114.116.254.193:42130';//新开发测试环 境
//sysConfig.testHost = '101.227.240.166:58090';//生产环 境
// sysConfig.testHost = '49.4.2.125:58090';//准生产环 境
sysConfig.testHost = '120.52.136.2:10269';//验收环 境
//sysConfig.testHost = '192.168.1.128:8016';//本地环境
//web的服务器端IP
sysConfig.serverUrl = "http://" + sysConfig.host + "/itower/mobile/app/service";
//web的测试端服务器Ip
sysConfig.serverUrl_test = "http://" + sysConfig.testHost + "/itower/mobile/app/service";

//web端的正式服务器IP
sysConfig.serverUrl_main = "http://" + sysConfig.host + "/itower/mobile/app/service";
if("180.153.49.253:58090"==sysConfig.host){
sysConfig.serverUploadUrl = "http://180.153.49.251:59015/itower/mobile/app/projectUnpressImgUpload";
}else{
sysConfig.serverUploadUrl = "http://" + sysConfig.host + "/itower/mobile/app/projectUnpressImgUpload";
}
//if("101.227.240.166:58090"==sysConfig.testHost){
//sysConfig.serverUploadUrl_test = "http://180.153.49.251:59015/itower/mobile/app/projectUnpressImgUpload";
//}else{
sysConfig.serverUploadUrl_test = "http://" + sysConfig.testHost + "/itower/mobile/app/projectUnpressImgUpload";
//}

sysConfig.serverDownUrl = "http://" + sysConfig.host + "/itower/mobile/app/projectImgDownload";

sysConfig.serverDownUrl_test = "http://" + sysConfig.testHost + "/itower/mobile/app/projectImgDownload";

sysConfig.pushLogUrl = "http://" + sysConfig.host + "/itower/jf/push/pushReceive";
sysConfig.pushLogUrl_test = "http://" + sysConfig.testHost + "/itower/jf/push/pushReceive";

sysConfig.appDownUrl = "http://" + sysConfig.host + "/itower/mobile/clientapi";
sysConfig.appDownUrl_test = "http://" + sysConfig.testHost + "/itower/mobile/clientapi";

/**
 *log测试地址
 */
logDebugServerUrl = "http://192.168.31.169:8080/itower/jf/sysLog/console";

function changeHost(host) {
    sysConfig.host = host;
    sysConfig.serverUrl = "http://" + host + "/itower/mobile/app/service";
    if('180.153.49.253:58090'==host){
    sysConfig.serverUploadUrl = "http://180.153.49.251:59015/itower/mobile/app/projectUnpressImgUpload";
    }else{
     sysConfig.serverUploadUrl = "http://" + host + "/itower/mobile/app/projectUnpressImgUpload";
    }
    sysConfig.serverDownUrl = "http://" + host + "/itower/mobile/app/projectImgDownload";
    sysConfig.pushLogUrl = "http://" + host + "/itower/jf/push/pushReceive";
    sysConfig.appDownUrl = "http://" + host + "/itower/mobile/clientapi";
}

function changeTestHost(testHost) {
    sysConfig.testHost = testHost;
    sysConfig.serverUrl_test = "http://" + testHost + "/itower/mobile/app/service";
    sysConfig.serverUploadUrl_test = "http://" + testHost + "/itower/mobile/app/projectUnpressImgUpload";
    sysConfig.serverDownUrl_test = "http://" + testHost + "/itower/mobile/app/projectImgDownload";
    sysConfig.pushLogUrl_test = "http://" + testHost + "/itower/jf/push/pushReceive";
    sysConfig.appDownUrl_test = "http://" + testHost + "/itower/mobile/clientapi";
}

var refreshHostTimer = window.setTimeout(function() {
    var hostStorages = $api.getStorage('hostStorages') || {};
//  $.getJSON('http://180.153.49.253:58090/iplist.json', function(hostStorages) {
//      if ( typeof hostStorages != 'undefined') {
//          $api.setStorage('hostStorages', hostStorages);
//      }
//      var hostUnit = $api.getStorage('hostUnit');
//      changeHost(hostStorages[hostUnit]);
//  });
    api.ajax({
        url : 'http://180.153.49.253:58090/iplist.json'
    }, function(ret, err) {
        if (ret) {
            if (ret.body) {
                hostStorages = ret;
                if ( typeof hostStorages != 'undefined') {
                    $api.setStorage('hostStorages', hostStorages);
                }
                var hostUnit = $api.getStorage('hostUnit');
                changeHost(hostStorages[hostUnit]);
            }
        } else {
            api.toast({
                msg : err.msg
            });
        }
    });
}, 60 * 60 * 1000);
